/*
 * Created on 2005-1-2
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package nc.tb.ctl;

import nc.tb.cube.INtbSheetObject;
import nc.tb.pub.NtbEnv;
import nc.tb.pub.cache.CacheAccess;
import nc.tb.pub.cache.CacheAccessFactory;
import nc.tb.pub.cache.CacheException;
import nc.tb.pub.lang.NtbBSLangRes;
import nc.ui.pub.ClientEnvironment;
import nc.vo.pub.BusinessException;

/**
 * @author tzj
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class CTLBase {
	protected static String getLoginUserName(){
		//if in UI
		String sName="tbadmin";
		if(NtbEnv.isUICall()){
			if(ClientEnvironment.getInstance().getUser()!=null){
				sName = ClientEnvironment.getInstance().getUser().getUserName()
						+ "["+ ClientEnvironment.getInstance().getUser().getPrimaryKey()+ "]";
			}
		}
		return sName;
	}

	protected static void validateISO(INtbSheetObject iso) throws BusinessException, CacheException {
		if(NtbEnv.isUICall()){
			CacheAccess ca = CacheAccessFactory.getCacheAccess();
			Object o = ca.get(iso.getPrimaryKey());
			if (o != iso)
				throw new BusinessException(NtbBSLangRes.getInstance().getStrByID("UPPntbbs-000109"));
		}
	}
}
